package com.gin.kotlin.no_gay_alliance.database.entity

import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.gin.nga.enums.NoticeType
import com.gin.nga.response.notice.NoticeMessage
import kotlinx.parcelize.Parcelize
import java.time.ZonedDateTime

/**
 * 提醒消息
 * @property uuid 唯一id，根据类型和时间生成
 * @property userId 消息所有者的用户ID
 * @property type 消息类型
 * @property fromUid 来源用户id
 * @property fromUname 来源用户名
 * @property toUid 目标用户id
 * @property toUname 目标用户名
 * @property text 文本1, 可能对应： 主题标题
 * @property aboutId 相关ID1， 可能对应：主题ID，私信ID
 * @property aboutId2 相关ID2， 可能对应：来源回复ID
 * @property aboutId3 相关ID3， 可能对应：目标回复ID
 * @property time 时间戳
 * @property aboutId4 相关ID3， 可能对应：页码
 * @property text2 文本2,举报相关 可能对应：举报理由
 * @property text3 文本3,举报相关
 * @property description 默认描述信息
 * @property unread 未读标记
 * @constructor
 */
@Entity
@Parcelize
data class NoticeMsg(
    @PrimaryKey
    var uuid: String,
    @ColumnInfo(index = true)
    var userId: Long,
    var unread: Boolean,
    var type: NoticeType? = null,
    var fromUid: Long? = null,
    var fromUname: String? = null,
    var toUid: Long? = null,
    var toUname: String? = null,
    var text: String? = null,
    var aboutId: Long? = null,
    var aboutId2: Long? = null,
    var aboutId3: Long? = null,
    var time: ZonedDateTime? = null,
    var aboutId4: Long? = null,
    var text2: String? = null,
    var text3: String? = null,
    var description: String? = null,
) : Parcelable {

    constructor(data: NoticeMessage, userId: Long) : this(
        uuid = "${userId}_${data.type?.id}_${data.time?.toEpochSecond()}",
        userId = userId,
        unread = true,
        type = data.type,
        fromUid = data.fromUid,
        fromUname = data.fromUname,
        toUid = data.toUid,
        toUname = data.toUname,
        text = data.text,
        aboutId = data.aboutId,
        aboutId2 = data.aboutId2,
        aboutId3 = data.aboutId3,
        time = data.time,
        aboutId4 = data.aboutId4,
        text2 = data.text2,
        text3 = data.text3,
        description = data.obtainDescription(),
    )
}
